/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.cms.web;

import java.util.Date;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import org.fyx.cms.ejb.CmsLocal;
import org.fyx.cms.entity.CmsArticle;
import org.fyx.linker.web.LinkerLocal;
import org.fyx.mula.ejb.MulaLocal;
import org.fyx.web.context.WebContext;
import org.fyx.web.context.WebPage;

/**
 *
 * @author ydenek
 */
@ManagedBean
@SessionScoped
public class CmsArticleShow {

    @EJB
    private CmsLocal cms;
    @EJB
    private MulaLocal mula;
    @EJB
    private LinkerLocal linker;
    private CmsArticle article;

    /** Creates a new instance of CmsArticleShow */
    public CmsArticleShow() {
    }

    public void initArticle(int idArticle) {
        if (idArticle == 0) {
            FacesMessage msg = new FacesMessage(mula.get("Select the article."),
                    mula.get("You must select article."));
            WebContext.getMessages().add(msg);
            WebPage.redirect(linker.getLink("cms/list.xhtml"));
            article = new CmsArticle();
            return;
        }
        article = cms.getArticleById(idArticle);
    }

    public CmsArticle getArticle() {
        return article;
    }

    public Date getLastModification() {
        return article.getTimeEditation() == null ? article.getTimeCreate() : article.getTimeEditation();
    }
}
